package com.aistar.service.impl;

import com.aistar.mapper.CommentImagesMapper;
import com.aistar.pojo.CommentImages;
import com.aistar.repository.CommentImagesRepository;
import com.aistar.service.CommentImagesService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentImagesServiceImpl implements CommentImagesService {

    @Autowired
    private CommentImagesMapper commentImagesMapper;

    @Autowired
    private CommentImagesRepository commentImagesRepository;


    //根据评论id获取到对应的图片集合
    @Override
    public ServerResponse getAllByCommentId(Integer commentId) {
        Integer commentImagesStatus = 1;
        List<CommentImages> commentImagesList = commentImagesRepository.findAllByCommentIdAndCommentImagesStatus(commentId,commentImagesStatus);

        /*List<CommentImages> commentImagesList1 = null;
        for (CommentImages commentImages : commentImagesList){
            if (commentImages.getCommentImagesStatus()==1)
                commentImagesList1.add(commentImages);
        }*/
        if (commentImagesList != null && commentImagesList.size()>0){
            return ServerResponse.getDataSuccess(commentImagesList);
        }else {
            return ServerResponse.getDataFailed("没查询到");
        }
    }

    //添加
    @Override
    public ServerResponse save(CommentImages commentImages) {
        CommentImages save = commentImagesRepository.save(commentImages);
        if (save!=null)
            return ServerResponse.addSuccess();
        else
            return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse modifyStatus(CommentImages commentImages) {
        return null;
    }

    @Override
    public ServerResponse modify(CommentImages commentImages) {
        return null;
    }

    @Override
    public ServerResponse getById(Integer id) {
        return null;
    }

    @Override
    public ServerResponse getAll() {
        return null;
    }
}
